package com.spring.bean.page;

import java.io.Serializable;
import java.util.List;

import com.spring.utils.Constants;

public class PageView<T> implements Serializable {

	/* 分页数据 */
	private List<T> records;
	/* 获取开始页码和结束页码 */
	private PageIndex pageIndex;
	/* 总页数 */
	private long totalPage = 1;
	/* 每页显示条数 */
	private int maxResult = Constants.MAX_RESULT;
	/* 当前页 */
	private int currentPage = 1;
	/* 总记录数 */
	private long totalNum;
	/* 页码数量 */
	private int pagecode = Constants.PAGE_CODE;

	public PageView() {
	}

	public PageView(List<T> records, int currentPage) {
		this.records = records;
		this.currentPage = currentPage;
	}

	public List<T> getRecords() {
		return records;
	}

	public void setRecords(List<T> records) {
		this.records = records;
	}

	public PageIndex getPageIndex() {
		return pageIndex;
	}

	public void setPageIndex(PageIndex pageIndex) {
		this.pageIndex = pageIndex;
	}

	public long getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(long totalPage) {
		this.totalPage = totalPage;
		this.pageIndex = PageIndex.getPageIndex(pagecode, currentPage, totalPage);
	}

	public int getMaxResult() {
		return maxResult;
	}

	public void setMaxResult(int maxResult) {
		this.maxResult = maxResult;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public long getTotalNum() {
		return totalNum;
	}

	/* 获取到totalNum后进行页面数量的计算 */
	public void setTotalNum(long totalNum) {
		this.totalNum = totalNum;
		setTotalPage(this.totalNum%this.maxResult==0?this.totalNum/this.maxResult:this.totalNum/this.maxResult+1);
	}

	public int getPagecode() {
		return pagecode;
	}

	public void setPagecode(int pagecode) {
		this.pagecode = pagecode;
	}

}
